<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>在线玩家 -- </title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css">
		<style type="text/css">
		</style>

	</head>

	<body>
	    <br/>
		<form class="layui-form" action="" onsubmit='return false;'>
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" name="test" id="test" placeholder="账号/ID/昵称" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-inline">
					<div class="layui-input-inline">
						<select name="Room" id="Room" lay-filter="Room">
						    <option value="全部房间">全部房间</option>
						</select>
					</div>
				</div>
				
				<div class="layui-inline">
					<div class="layui-input-inline">
						<select name="Businessman" id="Businessman" lay-filter="Businessman">
						    <option value="0">全部</option>
						    <option value="1">普通玩家</option>
						    <option value="2">会长</option>
						</select>
					</div>
				</div>

				<div class="layui-inline">
					<div class="layui-input-inline">
						<button class="layui-btn layui-btn-normal" data-type="reload" lay-filter="findID" id="findID">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</div>
		</form>
		<div class="layui-form" id="table-list">
			<table class="layui-table" lay-skin="nob" id="onlineTable" lay-filter="onlineTable"></table>
		</div>
		
		<script type="text/html" id="IsBusinessman">
            {{#  if(d.IsBusinessman === false){ }}
                <span class="layui-badge layui-bg-green">玩家</span>
            {{#  } else if(d.IsBusinessman === true){ }}
                <span class="layui-badge layui-bg-blue">会长</span>
            {{#  } }}
        </script>
        
        
		<script type="text/html" id="tool">
<%--			<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>--%>
            {{#  if(d.IsBlocked == 0){ }}
                 <a class="layui-btn layui-btn-xs" lay-event="edit">未锁定</a>
              {{#  } else { }}
                 <a class="layui-btn layui-btn-xs" lay-event="edit2">已锁定</a>
              {{#  } }}
        </script>
        
        <script type="text/html" id="RealGain">
            {{#  d.RealGain = d.TotalCurrencyWin - d.TotalCurrencyLost }}
                 <span>{{ d.RealGain }}</span>
            {{#  }}
        </script>
        
        <script type="text/html" id="TotalRecharge">
            {{#  d.TotalRecharge = d.TotalRecharge/100 }}
                <span>{{ d.TotalRecharge }}</span>
            {{#  }}
        </script>
        
        <script type="text/html" id="PersonalInRecoverState">
            {{#  if(d.PersonalInRecoverState === false){ }}
                <span style="color:#1d953f">否</span>
            {{#  } else if(d.PersonalInRecoverState === true){ }}
                <span style="color:#ed1941">回血</span>
            {{#  } }}
        </script>
        
        <script type="text/html" id="StrongDifficultyLevel">
            {{#  if(d.StrongDifficultyLevel === 0){ }}
                <span class="layui-badge">极难</span>
            {{#  } else if(d.StrongDifficultyLevel === 1){ }}
                <span class="layui-badge">很难</span>
            {{#  } else if(d.StrongDifficultyLevel === 2){ }}
                <span class="layui-badge">难</span>
            {{#  } else if(d.StrongDifficultyLevel === 4){ }}
                <span class="layui-badge layui-bg-green">易</span>
            {{#  } else if(d.StrongDifficultyLevel === 5){ }}
                <span class="layui-badge layui-bg-green">很容易</span>
            {{#  } else if(d.StrongDifficultyLevel === 6){ }}
                <span class="layui-badge layui-bg-green">极易</span>
            {{#  } else if(d.StrongDifficultyLevel === -1){ }}
                <span class="layui-badge layui-bg-green">默认</span>
            {{#  } }}
        </script>
        <script type="text/html" id="PersonalDifficultyLevel">
            {{#  if(d.PersonalDifficultyLevel === 0){ }}
                <span style="color:#ed1941">极难</span>
            {{#  } else if(d.PersonalDifficultyLevel === 1){ }}
                <span style="color:#ef4136">很难</span>
            {{#  } else if(d.PersonalDifficultyLevel === 2){ }}
                <span style="color:#d93a49">难</span>
            {{#  } else if(d.PersonalDifficultyLevel === 4){ }}
                <span style="color:#00ae9d">易</span>
            {{#  } else if(d.PersonalDifficultyLevel === 5){ }}
                <span style="color:#45b97c">很容易</span>
            {{#  } else if(d.PersonalDifficultyLevel === 6){ }}
                <span style="color:#1d953f">极易</span>
            {{#  } else if(d.PersonalDifficultyLevel === -1){ }}
                <span>默认</span>
            {{#  } }}
        </script>
        
        <script type="text/html" id="PersonalMaxPrizePool">
            <span class="layui-badge layui-bg-green">{{ d.PersonalMaxPrizePool }}</span>
        </script>
        
        <script type="text/html" id="VipExp">
            <span class="layui-badge layui-bg-green">{{ d.VipExp }}</span>
        </script>
        
		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script src="js/frame/form_upload.js"></script>
		<script src="js/frame/datagrid.js"></script>
		<script src="js/common/monitor_back.js"></script>
		<script>
			layui.use(['layer', 'form', 'table', 'laytpl'], function() {
				var layer = layui.layer,
					form = layui.form,
					table = layui.table,
					laytpl = layui.laytpl;

				layer.config({
					extend: 'MySkin/style.css'
				});
				
				
				//页面加载完成执行动作
				$(document).ready(function(){
					$.post("playeronline/room",function(status){
						if(status != null || status != ""){
							data = jQuery.parseJSON(status);//json对象
							//$("#ChooseGoods").empty();//清空select
							for(var i = 0, l = data.length;i < l;i++){
								for(var key in data[i]){
									if(data[i][key] === '全部房间')
										continue;
									$("#Room").append("<option value="+ data[i][key] +">" + data[i][key] + "</option>");
									form.render();
								}
							}
						}else{
							layer.msg("加载失败,请刷新页面",{icon:2});
						}
					});
				});

				//加个table表
				table.render({
					elem: '#onlineTable',
					url: 'pa/onlinelist',
					method: 'post',
					title: '玩家资源变化',
					totalRow: true,
					autoSort: false,
					cellMinWidth: 120, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					id: 'AllTable',
					request: {
						pageName: 'PageIndex',
						limitName: 'PageCount'
					},
					where: {
						Room: $('#Room').val(),
						Businessman : $('#Businessman').val()
					},
					cols: [[
						{field: 'Id',title: 'ID',event:'ViewUserMessage',style: "color: #0000ff;"},
						{field: 'Nickname',title: '昵称',hide:true}, 
						{field:'Level',title:'等级',sort:true},
						{field:'VipLevel',title:'VIP等级'},
						{field:'VipExp',title:'VIP经验',templet:'#VipExp',event:'VipExpChange',templet:'#VipExp'},
						{field:'Diamond',title:'钻石',hide:true},
						{field:'ItemLock',title:'锁定',hide:true},
						{field:'ItemFreeze',title:'冰冻',hide:true},
						{field:'ItemSummon',title:'召唤',hide:true},
						{field:'ItemWild',title:'狂暴',hide:true},
						{field:'ItemShadow',title:'分身',hide:true},
						{field:'Item10',title:'防水木料',hide:true},
						{field:'Item11',title:'精炼矿石',hide:true},
						{field:'Item12',title:'海妖外壳',hide:true},
						{field:'Item13',title:'潮汐精粹',hide:true},
						{field:'Item14',title:'深海魔晶',hide:true},
						{field:'ItemMultipleHit',title:'倍击',hide:true},
						{field:'Integral',title:'积分',hide:true},
						{field:'ItemTicket',title:'奖券',hide:true},
						{field:'ItemWarhead1',title:'青铜',hide:true},
						{field:'ItemWarhead2',title:'白银',hide:true},
						{field:'ItemWarhead3',title:'黄金',hide:true},
						{field:'ItemWarhead4',title:'紫金',hide:true},
						{field:'IsBusinessman',title:'玩家/会长',templet:'#IsBusinessman',event:'setSign'},
						{field: 'LocationRoom',title: '所在游戏【房间】'},
						{field: 'Currency',title: '携带金币',sort: true},
						{field: 'BankCurrency',title: '金库金币',sort: true},
						{field:'StrongDifficultyLevel',title:'强控个人等级难度',templet:'#StrongDifficultyLevel',event:'StrongDifficultyLevel'},
						{field:'StrongDifficultyWinLost',title:'强控剩余输赢分数',templet:'#StrongDifficultyWinLost'},
						{field:'PersonalDifficultyLevel',title:'自控个人等级难度',sort:true,templet:'#PersonalDifficultyLevel'},
						{field:'PersonalCurrentPrizePool',title:'当前奖池'},
						{field:'PersonalMaxPrizePool',title:'奖池最大值',event:'setPool',style:"color:red",templet:'#PersonalMaxPrizePool'},
						{field:'PersonalRecoverPoint',title:'回血点数'},
						{field:'PersonalInRecoverState',title:'回血状态',templet:'#PersonalInRecoverState',style:"color:red"},
						{field: 'TotalCurrencyLost',title: '总输',sort: true,hide:true}, 
						{field: 'TotalCurrencyWin',title: '总赢',sort: true,hide:true},
						{field: 'RealGain',title: '总输赢',sort: true,templet:'#RealGain'},
						{field:'TotalRecharge',title:'充值',sort:true,templet:'#TotalRecharge'},
						{field: 'IsBlocked',title: '封禁',hide:true}, 
						{field: 'CheatMode',title: '调整(数量/类型)',hide:true},
						{field:'LastLoginTime',title:'最后登陆时间',hide:true},
						{field:'LastLoginIp',title:'最后登录IP',hide:true},
						{field:'Phone',title:'绑定的手机号码',hide:true},
						{field:'BankPassword',title:'金库密码',hide:true},
					    {title: '操作',fixed: 'right',width: 80,toolbar: '#tool'}
						]],
					page:{
						limit: 30,
						limits: [10, 20, 30, 40, 50],
					}, //分页
					response: {
						statusCode: 200
						//重新规定成功的状态码为 200，table 组件默认为 0
					},
					parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
						console.log(res);
						for (var i = 0; i < res.data.length; i++) {
							for (var key in res.data[i]) {
								if (res.data[i][key] == null) {
									res.data[i][key] == '无';
								}
							}
						}
						return {
							"code": res.status, //解析接口状态
							"msg": res.message, //解析提示文本
							"count": res.count, //解析数据长度
							"data": res.data //解析数据列表
							//解析数据列表
						};
					}
				});

				//根据条件查询表格数据重新加载
				var active = {
					reload: function() {
						//获取用户名
						//执行重载
						table.reload('AllTable', {
							page: {
								curr: 1 //重新从第 1 页开始
							}
							//根据条件查询
							,
							where: {
								UserId: $('#test').val(),
								Room: $('#Room').val(),
								Businessman : $('#Businessman').val()
							}
						});
						return false;
					}
				};
				//点击搜索按钮根据用户名称查询
				$('#findID').on('click',
					function() {
						var type = $(this).data('type');
						active[type] ? active[type].call(this) : '';
					});

				//监听行工具事件
				  table.on('tool(onlineTable)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
				  	if (history.state == null){
				  		pushHistory();
					}
				    var data = obj.data //获得当前行数据
				    ,layEvent = obj.event; //获得 lay-event 对应的值
					  var id = data.Id;
					  var Nickname = data.Nickname;
					  var RegisterIp = data.RegisterIp;
					  var LastLoginIp = data.LastLoginIp;
					  var Diamond = data.Diamond;
					  var ItemLock = data.ItemLock;
					  var ItemFreeze = data.ItemFreeze;
					  var ItemSummon = data.ItemSummon;
					  var ItemWild = data.ItemWild;
					  var ItemShadow = data.ItemShadow;
					  var Item10 = data.Item10;
					  var Item11 = data.Item11;
					  var Item12 = data.Item12;
					  var Item13 = data.Item13;
					  var Item14 = data.Item14;
					  var ItemMultipleHit = data.ItemMultipleHit;
					  var Integral = data.Integral;
					  var ItemTicket = data.ItemTicket;
					  var ItemWarhead1 = data.ItemWarhead1;
					  var ItemWarhead2 = data.ItemWarhead2;
					  var ItemWarhead3 = data.ItemWarhead3;
					  var ItemWarhead4 = data.ItemWarhead4;
					  var Phone = data.Phone;
					  var BankPassword = data.BankPassword;
					  var Currency = data.Currency;
					  var VipLevel = data.VipLevel;
					  var PersonalCurrentPrizePool = data.PersonalCurrentPrizePool;
					  var TotalRecharge = data.TotalRecharge / 100 +"."+ data.TotalRecharge % 100;
					  var RegisterTime = data.RegisterTime;
					  var LastLoginTime = data.LastLoginTime;
					  var PersonalInRecoverState = data.PersonalInRecoverState === true ? "回血" : "否";
					  var RealGain = data.TotalCurrencyWin - data.TotalCurrencyLost;
					  var BankCurrency = data.BankCurrency;
					  var PersonalMaxPrizePool = data.PersonalMaxPrizePool;

				    if(layEvent === 'detail'){
						var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['100%', '100%'],
							title: "查看玩家信息",
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/playRecords',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index);
								// 取到弹出层里的元素，并把编辑的内容放进去
								body.find(".UserId").html(id); //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
								body.find(".zlastLoginIp").html(LastLoginIp);
								body.find("#nickname").html(Nickname);
								body.find("#RegisterIp").html(RegisterIp);

								body.find(".Diamond").html(Diamond);
								body.find("#ItemLock").html(ItemLock);
								body.find("#ItemFreeze").html(ItemFreeze);
								body.find("#ItemSummon").html(ItemSummon);
								body.find("#ItemWild").html(ItemWild);
								body.find("#ItemShadow").html(ItemShadow);
								body.find("#Item10").html(Item10);
								body.find("#Item11").html(Item11);
								body.find("#Item12").html(Item12);
								body.find("#Item13").html(Item13);
								body.find("#Item14").html(Item14);
								body.find("#ItemMultipleHit").html(ItemMultipleHit);
								body.find("#Integral").html(Integral);
								body.find("#ItemTicket").html(ItemTicket);
								body.find("#ItemWarhead1").html(ItemWarhead1);
								body.find("#ItemWarhead2").html(ItemWarhead2);
								body.find("#ItemWarhead3").html(ItemWarhead3);
								body.find("#ItemWarhead4").html(ItemWarhead4);
								body.find("#Phone").html(Phone);
								body.find("#BankPassword").html(BankPassword);
								body.find("#Currency").html(Currency);
								body.find("#VipLevel").html(VipLevel);
								body.find("#PersonalCurrentPrizePool").html(PersonalCurrentPrizePool);
								body.find("#TotalRecharge").html(TotalRecharge);
								body.find("#RegisterTime").html(RegisterTime);
								body.find("#LastLoginTime").html(LastLoginTime);
								body.find("#PersonalInRecoverState").html(PersonalInRecoverState);
								body.find("#RealGain").html(RealGain);
								body.find("#BankCurrency").html(BankCurrency);
								body.find("#PersonalMaxPrizePool").html(PersonalMaxPrizePool);
							},
							cancel:function(){
								window.history.back();
							}
						});
				    } else if(layEvent === 'adjust'){
				    	var id = data.Id;
						var name = data.Nickname;
						var currency = data.Currency;
						var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['1500px', '800px'],
							title: '调整玩家上下分',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/playAdjustment',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								body.find(".zid").val(id);
								body.find(".zname").val(name);
								body.find("#Currency").val(currency);
							},
							cancel:function(){
								window.history.back();
							}
				      });
				    } else if(layEvent === 'edit'){
				        var id = data.Id;
						var name = data.Nickname;
						var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['100%', '100%'],
							title: '锁定玩家',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/playBlock',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index);
								// 取到弹出层里的元素，并把编辑的内容放进去
								body.find(".zid").val(id); //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
								body.find(".zname").val(name);
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'edit2'){
				    	var id = data.Id;
						var name = data.Nickname;
						var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['100%', '100%'],
							title: '解锁玩家',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/playUnBlock',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								// 取到弹出层里的元素，并把编辑的内容放进去
								body.find(".zid").val(id); //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
								body.find(".zname").val(name);
								//parent.layer.close(index);//关闭子页面
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'setSign'){
				    	var id = data.Id;
				    	var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['500px', '200px'],
							title: '设置会长',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/setBusinessman',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								body.find(".zid").val(id); 
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'VipExpChange'){
				    	var id = data.Id;
				    	var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['500px', '200px'],
							title: '充值Vip经验',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/setVip',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								body.find(".zid").val(id); 
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'StrongDifficultyLevel'){
				    	var id = data.Id;
				    	var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['100%', '400px'],
							title: '强控个人难度',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/setPlayerDifficult',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								body.find(".zid").val(id); 
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'setPool'){
				    	var id = data.Id;
				    	var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['500px', '200px'],
							title: '设置个人奖池',
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/setPool',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index); //绑定父子页面
								body.find(".zid").val(id); 
							},
							cancel:function(){
								window.history.back();
							}
						});
				    }else if(layEvent === 'ViewUserMessage'){
						var index = layer.open({
							type: 2,
							shadeClose: true,
							shade: 0.5,
							area: ['100%', '100%'],
							title: "查看玩家信息",
							skin: 'layer-ext-yourskin',
							content: '<%=basePath%>pa/detail/playRecords',
							success: function(layero, index) {
								var body = layer.getChildFrame("body", index);
								// 取到弹出层里的元素，并把编辑的内容放进去
								body.find(".UserId").html(id); //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
								body.find(".zlastLoginIp").html(LastLoginIp);
								body.find("#nickname").html(Nickname);
								body.find("#RegisterIp").html(RegisterIp);

								body.find(".Diamond").html(Diamond);
								body.find("#ItemLock").html(ItemLock);
								body.find("#ItemFreeze").html(ItemFreeze);
								body.find("#ItemSummon").html(ItemSummon);
								body.find("#ItemWild").html(ItemWild);
								body.find("#ItemShadow").html(ItemShadow);
								body.find("#Item10").html(Item10);
								body.find("#Item11").html(Item11);
								body.find("#Item12").html(Item12);
								body.find("#Item13").html(Item13);
								body.find("#Item14").html(Item14);
								body.find("#ItemMultipleHit").html(ItemMultipleHit);
								body.find("#Integral").html(Integral);
								body.find("#ItemTicket").html(ItemTicket);
								body.find("#ItemWarhead1").html(ItemWarhead1);
								body.find("#ItemWarhead2").html(ItemWarhead2);
								body.find("#ItemWarhead3").html(ItemWarhead3);
								body.find("#ItemWarhead4").html(ItemWarhead4);
								body.find("#Phone").html(Phone);
								body.find("#BankPassword").html(BankPassword);
								body.find("#Currency").html(Currency);
								body.find("#VipLevel").html(VipLevel);
								body.find("#PersonalCurrentPrizePool").html(PersonalCurrentPrizePool);
								body.find("#TotalRecharge").html(TotalRecharge);
								body.find("#RegisterTime").html(RegisterTime);
								body.find("#LastLoginTime").html(LastLoginTime);
								body.find("#PersonalInRecoverState").html(PersonalInRecoverState);
								body.find("#RealGain").html(RealGain);
								body.find("#BankCurrency").html(BankCurrency);
								body.find("#PersonalMaxPrizePool").html(PersonalMaxPrizePool);
							},
							cancel:function(){
								window.history.back();
							}
						});
					}
				  });
                setInterval(function(){
                	$.post("playeronline/room",function(status){
						if(status != null || status != ""){
							data = jQuery.parseJSON(status);//json对象
							$("#Room").empty();//清空select
							for(var i = 0, l = data.length;i < l;i++){
								for(var key in data[i]){
									$("#Room").append("<option value="+ data[i][key] +">" + data[i][key] + "</option>");
									form.render();
								}
							}
						}else{
							layer.msg("加载失败,请刷新页面",{icon:2});
						}
					});
                	
                	table.reload('AllTable', {});
                },60000);
                
                table.on('sort(onlineTable)',function(obj){
                	table.reload('AllTable',{
                		initSort:obj //记录初始排序，如果不设的话，将无法标记表头的 排序状态 
                		,where : {
                			field:obj.field    //排序字段
							,order:obj.type    //排序方式
                	    }
                	});
                });
                
                
			});
		</script>
	</body>
</html>
